<?php
require_once("DButil.php");
$conn = getConn();
$loginName=$_SESSION["name"];
// echo $loginName;
//获取登录的u_id
$sql="select u_id from t_user where u_login_name={$loginName}";
$result = mysqli_query($conn, $sql);
$uId=mysqli_fetch_assoc($result);
echo($uId["u_id"]);


$sql = "select o_no,count(o_num) o_num,count(o_num)*o_total o_total,u_id from t_order group by o_total having u_id={$uId["u_id"]}";
// echo $sql;
// echo "<br>";

$result = mysqli_query($conn, $sql);

// var_dump($result);
// echo "<br>";
// $row1=mysqli_fetch_assoc($result);
// print_r($row1);
// echo "<br>";
// $row2=mysqli_fetch_assoc($result);
// print_r($row2);
// echo "<br>";
// $row3=mysqli_fetch_assoc($result);
// print_r($row3);
// echo "<br>";
// $row4=mysqli_fetch_assoc($result);
// print_r($row4);
// echo "<br>";
// $row5=mysqli_fetch_assoc($result);
// print_r($row5);
// echo "<br>";
// $row6=mysqli_fetch_assoc($result);
// print_r($row6);
// echo "<br>";


// Array ( [o_no] => 20211314372 [o_num] => 2 [o_total] => 12 [u_id] => 3 )
// Array ( [o_no] => 202113141352 [o_num] => 12 [o_total] => 84 [u_id] => 3 )
// Array ( [o_no] => 20211314373 [o_num] => 3 [o_total] => 30 [u_id] => 3 )
// Array ( [o_no] => 202113142526 [o_num] => 3 [o_total] => 39 [u_id] => 3 )
// Array ( [o_no] => 20211314371 [o_num] => 2 [o_total] => 58 [u_id] => 3 )
// Array ( [o_no] => 202113143724 [o_num] => 2 [o_total] => 198 [u_id] => 3 )
if($result){
    echo "<form  action='detail.php' method='post'>";
    echo "<table border='1' cellpadding='10' cellspacing='0' >
    <thead>
        <tr>
            <td>订单业务编号</td>
            <td>总数量</td>
            <td>总金额</td>
            <td>所属用户</td>
        </tr>
    </thead>
    <tbody>";
    while($row = mysqli_fetch_assoc($result)) {
        // print_r($row);
        // echo "<br>";
        echo "<tr>
        <td>{$row['o_no']}</td>
        <td>{$row['o_num']}</td>
        <td>{$row['o_total']}</td>
        <td>{$row['u_id']}</td>
    </tr>";
    }
    echo "</tbody></table>";
    echo "<input type='submit' value='结算'>";
    echo "</form>";
}
mysqli_close($conn);
?>

